home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / tvx.arc / TVX-PTCH.C < prev    next >
C/C++ Source or Header  |  1989-07-30  |  8KB  |  365 lines

  1. /* --------------------------------- tvx_ptch.c --------------------------- */
  2. #include "tvx_defs.ic"
  3.  
  4. #define EXTERN
  5. #include "tvx_glbl.ic"
  6.  
  7. /*=======================================================================
  8.  
  9.     tvpatch - program to patch tvx with config.tvx file
  10.  
  11.     first version 6/19/84
  12.     7/25/84 - fixed to correspond to tvx version, add extra command
  13.     2/14/85 - version to correspond with rest
  14.     5/15/85 - again, batched to correspond
  15.     9/20/85 - fixed for new version of tvx, unix added
  16.  
  17. ======================================================================= */
  18.  
  19. #ifndef UNIX
  20.     char filein[] = "A:TVX.EXE";
  21.     char fileout[]= "A:TEMP1.$$$";
  22. #else
  23.     char filein[80] = "tvx";
  24.     char fileout[80]= "tvx_temp";
  25. #endif
  26.     char config[80];
  27.  
  28.  
  29. /*  define our general control item structure for general patching */
  30.  
  31. #define BL remark("")
  32. #define RMK remark
  33. #define PR prompt
  34.  
  35.     char clower(), cupper();
  36.     extern char *malloc();
  37.     extern FILE *fopen();
  38.     FILE *tvxin, *cfgin, *tvxout;
  39.  
  40. /* =============================>>> MAIN   <<<============================= */
  41.   main()
  42.   {
  43.  
  44.     char ans[80];
  45.  
  46. TOP:
  47.     cls();
  48.     RMK("TVX_PTCH - Version 11/12/85");
  49.     BL;
  50. RMK("  This program is used to permanently alter TVX to match the options");
  51. RMK("selected with the TVX_CNFG program.  It will read in the configuration");
  52. RMK("file you specify (such as CONFIG.TVX), and patch TVX to reflect those");
  53. RMK("values.  Then you won't need to use the '-c' switch when using TVX.");
  54.     BL;
  55. RMK("*** You may press CONTROL-C at any time to cancel this installation. ***");
  56.  
  57.     do 
  58.       {
  59.     BL;
  60. #ifndef UNIX
  61.     PR("On which drive is TVX.EXE located? (A, B, ...): ");
  62.     ureply(ans,10);
  63.     filein[0] = ans[0];
  64. #endif
  65.     if ( !(tvxin = fopen(filein,FILEREAD)))
  66.       {
  67.         PR("TVX not found on specified drive, try again: ");
  68.         RMK(filein);
  69. #ifdef UNIX
  70.         PR("Please enter name of tvx executable file: ");
  71.         reply(filein,79);
  72. #endif
  73.         continue;
  74.       }
  75.     fclose(tvxin);
  76.     break;
  77.       }
  78.     while (1);
  79.  
  80. #ifndef UNIX
  81.     fileout[0] = cupper(ans[0]);
  82. #endif
  83.  
  84.     do 
  85.       {
  86.     BL;
  87.     PR("Enter the name of the configuration file to use: ");
  88.     reply(config,79);
  89.     if ( !(cfgin = fopen(config,FILEREAD)))
  90.       {
  91.         RMK("Configuration not found on specified drive, try again.");
  92.         continue;
  93.       }
  94.  
  95.     rdcfg(lexsym,LEXVALUES+1);
  96.     rdcfg(synofr,20);
  97.     rdcfg(synoto,20);
  98.     rdcfg(funchar,50);
  99.     rdcfg(funcmd,50);
  100.     rdcfg(&funkey,1);
  101.     rdcfg(&autoin,1);
  102.     rdcfg(&ddline,1);
  103.     rdcfg(&dscrl,1);
  104.     rdcfg(&dxcase,1);
  105.     rdcfg(&wraplm,1);
  106.     rdcfg(&use_wild,1);
  107.     rdcfg(&usebak,1);
  108.     logdef = usebak;
  109. #ifdef MSDOS
  110.     rdcfg(&usecz,1);
  111. #endif
  112.     fclose(cfgin);
  113.     break;
  114.       }
  115.     while (1);
  116.  
  117.     BL;
  118.     RMK("TVX is being modified to match your choices.");
  119.     RMK("This may take several minutes.");
  120.     BL;
  121.  
  122.     fpatch(filein);    /* patch tvx */
  123.  
  124.     cls();
  125.     RMK("Modification completed.  TVX is ready to use without the -c now.");
  126.     BL;
  127.   }
  128.  
  129. /* =============================>>> RDCFG <<<============================= */
  130.   rdcfg(toset,cnt)
  131.   char *toset;
  132.   int cnt;
  133.     {    /* read cnt vals from cfgin */
  134.  
  135.     FAST int i,val;
  136.  
  137.     for (i = 0 ; i < cnt ; ++i)
  138.       {
  139.     if ((val = fgetc(cfgin)) == EOF)
  140.      {
  141.         remark("Invalid configuration file, aborting");
  142.         fclose(cfgin);
  143.         exit(999);
  144.      }
  145.     *toset++ = val;    /* replace with new commands */
  146.       }
  147.   }
  148.  
  149. /* =============================>>> FPATCH <<<============================= */
  150.   fpatch(fn)
  151.   char *fn;
  152.   {
  153.     static int byt;
  154.     static int i;
  155.     static int didpatch;
  156.     static char *begptr;    /* patch area pointers */
  157.  
  158.     prompt("Patching "); remark(filein);
  159.  
  160. #ifndef UNIX
  161.     fn[0] = fileout[0];        /* set drive */
  162. #endif
  163.     didpatch = FALSE;
  164.     if (!(tvxin = fopen(fn,FILEREAD)))
  165.       {
  166.     PR("Unable to find file to patch: "); PR(fn);
  167.         RMK(".  Aborting to operating system.");
  168.     exit(999);
  169.       }
  170.     if (!(tvxout = fopen(fileout,FILEWRITE)))
  171.       {
  172.     PR("Unable to create new file, aborting: ");
  173.     RMK(fileout);
  174.     exit(999);
  175.       }
  176.  
  177.     while ((byt = fgetc(tvxin)) != EOF)
  178.       {
  179.     fputc(byt,tvxout);
  180.     if (byt == '#')            /* look for first sharp */
  181.       {
  182.         for (i = 1 ; i <= 4 ; ++i)
  183.           {
  184.         if ((byt = fgetc(tvxin)) == EOF)
  185.             goto l900;
  186.         fputc(byt,tvxout);    /* echo */
  187.         if (byt != '#')
  188.             goto l800;
  189.           }
  190.         byt = fgetc(tvxin);        /* should be : next */
  191.         fputc(byt,tvxout);
  192.         if (byt != ':')
  193.         goto l800;
  194.  
  195. /*   fall thru means found patch area -- code to patch follows */
  196.  
  197.         for (begptr = (char *) &addx ; begptr < (char *) &endpatch ;
  198.           ++begptr)
  199.           {
  200.         if ((byt = fgetc(tvxin)) == EOF) /* read byte from file */
  201.             goto l900;
  202.         fputc(*begptr,tvxout); /* replace with byte from my area */
  203.           }
  204.         didpatch = TRUE;
  205.       }
  206. l800:    byt = byt;        /* compiler bug */
  207.       }
  208.  
  209.  
  210. l900:
  211.     fclose(tvxin);
  212.     fclose(tvxout);
  213.     if (!didpatch)
  214.       {
  215.     RMK("*********  ERROR ********");
  216.     RMK("The file just checked was not a proper version of the program!");
  217.     RMK("Please check that your are using a valid copy of the");
  218.     RMK("program file supplied with this initialization program!");
  219.     RMK("Unable to make patch, aborting");
  220.     exit(999);
  221.       }
  222.     unlink(fn);
  223.     fn[0] = fileout[0];        /* fix the drive */
  224.     if (rename(fileout,fn) != 0)
  225.       {
  226.     RMK("Unable to rename temporary patch file");
  227.     exit(999);
  228.       }
  229.   }
  230.  
  231. /* =============================>>> OK <<<============================= */
  232.   ok(msg)
  233.   char *msg;
  234.   {
  235.     char rp[11];
  236.     PR(msg); PR(" (y/n) ");
  237.     lreply(rp,10);
  238.     return (rp[0] == 'y');
  239.   }
  240.  
  241. /* ============================>>> RVALID <<<=========================== */
  242.   rvalid(chr,okstr)
  243.   char chr,*okstr;
  244.   {
  245.     /* sees if chr is in okstr */
  246.    
  247.     SLOW int i;
  248.     SLOW char ch;
  249.  
  250.     ch = clower(chr);
  251.     while (*okstr)
  252.       {
  253.     if (ch == clower(*okstr++))
  254.         return TRUE;
  255.       }
  256.     return FALSE;
  257.   }
  258.   
  259. /* =============================>>> CLS  <<<============================= */
  260.   cls()
  261.   {
  262.     int i;
  263.  
  264.     for (i = 0  ; i < 25 ; ++i)
  265.     BL;
  266.   }
  267.  
  268. #define EXTENDED    /* my own extended lib functions */
  269. /* #define STANDARD    /* the set of standard functions i use */
  270. #define LOCAL static    /* make all local globals, i think */
  271.  
  272.  
  273. #ifdef EXTENDED
  274. /*=============================>>> CLOWER  <<<================================*/
  275.   char clower(ch)
  276.   char ch;
  277.   {
  278.     return ((ch >='A' && ch<='Z') ? ch + ' ' : ch);
  279.   }
  280.  
  281. /*=============================>>> CUPPER  <<<================================*/
  282.   char cupper(ch)
  283.   char ch;
  284.   {
  285.     return ((ch >= 'a' && ch <= 'z') ? ch - ' ' : ch);
  286.   }
  287.  
  288. /* =========================>>> LOWER  <<<==============================*/
  289.   lower(str)
  290.   char str[];
  291.   {
  292.     FAST int i;
  293.  
  294.     for (i=0 ; str[i] ; ++i)
  295.     str[i]=clower(str[i]);
  296.  
  297.   }
  298.  
  299. /*=============================>>> PROMPT <<<================================*/
  300.   prompt(msg)
  301.   char msg[];
  302.   {
  303.     printf("%s",msg);
  304.   }
  305.  
  306.  
  307. /*=============================>>> REMARK <<<================================*/
  308.   remark(msg)
  309.   char msg[];
  310.   {
  311.     printf("%s\n",msg);
  312.   }
  313.  
  314. /*=============================>>> UPPER  <<<================================*/
  315.   upper(str)
  316.   char str[];
  317.   {
  318.     static int i;
  319.  
  320.     for (i=0 ; str[i] ; ++i)
  321.     str[i]=cupper(str[i]);
  322.   }
  323.  
  324.  
  325. /*=============================>>> LREPLY <<<================================*/
  326.   lreply(msg,maxc)
  327.   char msg[];
  328.   int maxc;
  329.   {
  330.     reply(msg,maxc);
  331.     lower(msg);
  332.   }
  333.  
  334. /*=============================>>> UREPLY <<<================================*/
  335.   ureply(msg,maxc)
  336.   char msg[];
  337.   int maxc;
  338.   {
  339.     reply(msg,maxc);
  340.     upper(msg);
  341.   }
  342.  
  343. /*=============================>>> REPLY <<<================================*/
  344.   reply(msg,maxc)
  345.   char msg[];
  346.   int maxc;
  347.   {
  348. #ifdef UNIX
  349.     gets(msg);
  350. #else
  351.     gets(msg,maxc,stdin);
  352. #endif
  353.   }
  354.  
  355. /*=============================>>> RDINT <<<================================*/
  356.   rdint(val)
  357.   int *val;
  358.   {
  359.     char chrrep[12];
  360.     reply(chrrep,11);
  361.     *val = atoi(chrrep);
  362.   }
  363. #endif
  364. /* --------------------------------- tvx_ptch.c --------------------------- */
  365.